The present invention relates to memory management in an operating system. More specifically, the present invention relates to sharing of memory among multiple processes for facilitating concurrent execution of the multiple processes on the operating system.
Sharing memory is a method of inter-process communication, i.e., a way of sharing data among multiple processes running at the same time on an operating system of a computing device. Various operating systems such as Unix®, Windows, and Linux facilitate the sharing of memory to perform parallel processing of more than one application on the operating system.
Various conventional methods are used to facilitate the sharing of memory in real-time among multiple processes. One such conventional method uses memory mapping of the shared data. The operating system maps a file or a shared data object onto the virtual addresses of multiple processes, but at potentially different virtual addresses of the memory. In such cases, indirect pointer addressing is used to access the memory. The indirect pointers to the memory may be treated as offsets from the beginning of a virtual address of the memory. As a result, all references to data in the virtual addresses are made by adding an offset to the base of the mapped data. Further, all the references are returned separately to each of the multiple processes. This operation is slow and lacks convenience in comparison to direct pointer addressing. In addition, the pointers may not be saved to the shared memory, and may cause subtle bugs in the system.
In another conventional method, the operating system executes multi-threaded programming. In multi-threaded programming, multiple threads share the same address of the memory. However, writing via an incorrect pointer to the memory in a thread can corrupt data from another thread or other data that is not meant to be visible to other threads. Further, in the thread model, the size of available virtual address is limited to the amount addressable in a single address. In such a system, the amount of memory that can be allocated is limited to the available virtual address.
In case of a shared virtual address, the multiple processes need to make coordinated attempts to allocate memory in the shared address to exchange information through some external channel. Examples of external channels include, but are not limited to, file descriptors, sockets, and files. The multiple processes may keep trying to locate a corresponding suitable physical address of the memory. Alternatively, the processes involved may choose a single fixed physical address that works on a given machine, but may fail with slight changes to the operating system with the passage of time, causing unexpected program failure. Therefore, the process of sharing memory through the sharing of the virtual address is failure-prone.
In light of the foregoing discussion, there exists a need for a method and system that can efficiently manage addresses in a multi-processing environment. The operating system should preferably avoid the acquiring of multiple locks across the multiple processes to perform a single system call. Further, the operating system should preferably include high-performance techniques for allocating shared memory across multiple processes without the requirement to lock addresses of all the processes running on the operating system. Furthermore, there exists a need for a method and system that facilitates the direct pointer addressing to the memory. Furthermore, the method and system should preferably lower the risk of data corruption in the memory. Additionally, there exists a need for a method and system which can scale the amount of allocable memory in proportion to the number of processes running on the operating system and prevent performance loss.